#include <bits/stdc++.h>
using namespace std;

inline int _max(int a, int b) {
	if (a > b) {
		return a;
	} else {
		return b;
	}
}

int a[1005][1005] = {0};

int f[1005][1005] = {0};

int main() {

	int n;
	cin >> n;
	for (int i = 1; i <= n; i++) {
		for (int j = 1; j <= i; j++) {
			cin >> a[i][j];
			f[i][j] = a[i][j];
		}
	}
	for (int i = n - 1; i >= 1; i--) {
		for (int j = 1; j <= i; j++) {
			f[i][j] = _max(f[i + 1][j], f[i + 1][j + 1]) + a[i][j];
		}
	}
	cout << f[1][1];
	return 0;
}